import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/grid_view/heighted_grid_view.dart';
import 'package:pornhub_app/routes/routes.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/utils/utils.dart';
import 'package:pornhub_app/views/mine/profit/video/profit_video_list_controller.dart';

import '../../../../model/mine/profit_dynamic_item_model.dart';
import '../../../../utils/color.dart';

class ProfitVideoList extends StatelessWidget {
  const ProfitVideoList({super.key});

  _tap(ProfitDynamicItemModel item) {
    Get.toIncomeVideoDetail(videoId: item.id!, videoMark: 1);
  }

  _buildCover(ProfitDynamicItemModel item) {
    return Container(
      width: 99.w,
      height: double.infinity,
      clipBehavior: Clip.hardEdge,
      decoration: BoxDecoration(
          color: COLOR.color_666666, borderRadius: Styles.borderRadius.m),
      child: ImageView(src: item.image ?? '', fit: BoxFit.fill),
    );
  }

  _buildRight(ProfitDynamicItemModel item) {
    return Expanded(
      child: SizedBox(
        width: 180.w,
        height: 129.w,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              item.name ?? '',
              style: kTextStyle(COLOR.color_333333, fontsize: 13.w),
            ).marginOnly(top: 10.w),
            Text(
              '${Utils.dateFmt(item.createdAt ?? '')}发布',
              style: kTextStyle(COLOR.hexColor('#A4A4B2'), fontsize: 10.w),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  '总收益:',
                  style: kTextStyle(COLOR.hexColor('#A4A4B2'), fontsize: 10.w),
                ),
                SizedBox(width: 2.w),
                Text(
                  '${item.gold ?? 0}',
                  style: kTextStyle(COLOR.hexColor('#DD001B'), fontsize: 10.w),
                ),
                const Expanded(child: SizedBox()),
                Text(
                  '查看详情>',
                  style: kTextStyle(COLOR.color_333333, fontsize: 12.w),
                ),
              ],
            )
          ],
        ).marginOnly(left: 6.w),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final _ = Get.find<ProfitVideoListController>();
    return GetBuilder<ProfitVideoListController>(
      builder: (_) {
        return HeightedGridView.sliver(
          rowSepratorBuilder: (context, index) {
            return SizedBox(height: 14.w);
          },
          crossAxisCount: 1,
          itemCount: _.list.length,
          itemBuilder: (context, index) {
            final item = _.list[index];
            return SizedBox(
              height: 129.w,
              width: double.infinity,
              child: Row(
                children: [
                  _buildCover(item),
                  _buildRight(item),
                ],
              ),
            ).marginHorizontal(16.w).onOpaqueTap(() {
              _tap(item);
            });
          },
        );
      },
    );
  }
}
